﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GTAuto.DAL.Entities;
using GTAuto.DAL.Extensions;

namespace GTAuto.DAL.DAL
{
    public class DALSettngs : DALBase
    {
        public static DALSettngs Singleton = new DALSettngs();

        public GTSetting Get(string code)
        {
            using (var db = new GTAutoDataClassesDataContext(ConnectionString))
            {

                Setting brand;
                if(HttpContext.Current.Session["Setting_"+code]!=null )
                {
                    brand = (Setting) HttpContext.Current.Session["Setting_" + code];
                }
                else
                {
                    brand = db.Settings.SingleOrDefault(x => x.Code == code);
                    HttpContext.Current.Session["Setting_" + code] = brand;
                }
                
                GTSetting setting = new GTSetting();
                setting.UpdateTo(brand);
                return setting;
            }
        }

    }
}
